using System;
using System.Collections.Generic;
using System.Text;
using OpenALDotNet;
using OpenALDotNet.Streams;
using SlimDX;
using Barrage.Global;

namespace Barrage.Audios
{
    /// <summary>
    /// SimpleAudio is an audio with no spacialization or special characteristics.
    /// It simply loads the AudioFile and plays it on demand.
    /// </summary>
    public class SimpleAudio:Audio
    {
        AudioSource source;
        bool playing = false;
        /// <summary>
        /// Constructor. Loads the file buffer.
        /// </summary>
        /// <param name="file">AudioFile of the sound</param>
        public SimpleAudio(AudioFile file)
        {
            source = new AudioSource();
            source.EnqueueBuffer(file.Buffer);
            // Non spatialized sound
            source.IsRelative = false;
            // Do not loop by default
            source.IsLooping = false;
        }

        /// <summary>
        /// \internal This sound doesn't need any kind of update
        /// </summary>
        /// <param name="item">Item holding this sound</param>
        public override void Update(Item item){           
        }

        /// <summary>
        /// \internal Gets / Sets wether the sound should loop when finished
        /// </summary>
        public override bool Loop
        {
            get
            {
                return source.IsLooping;
            }
            set
            {
                source.IsLooping = value;
            }
        }

        /// <summary>
        /// \internal Gets/Sets the relative sound speed (1 is default)
        /// </summary>
        public override float Speed
        {
            get
            {
                return source.Pitch;
            }
            set
            {
                source.Pitch = value;
            }
        }

        /// <summary>
        /// \internal Starts the sound
        /// </summary>
        public override void Start()
        {
            source.Play();
            playing = true;
        }

        /// <summary>
        /// \internal Stops the sound
        /// </summary>

        public override void Stop()
        {
            source.Stop();
            playing = false;
        }

        /// <summary>
        /// \internal Returns true when the sound is being played
        /// </summary>
        public override bool Playing
        {
            get { return playing; }
        }

        /// <summary>
        /// \internal Gets / Sets the sound volume
        /// </summary>
        public override float Volume
        {
            get
            {
                return source.Gain;
            }
            set
            {
                source.Gain = value;
            }
        }
    }
}
